<template>
  <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="dealform" :model="model" :rules="rules" label-width="120px">
      <el-row>
        <!-- <el-col :span="12">
                    <el-form-item label="发票号码" prop="invoiceno" :rules="rules.validateRequire">
                        <el-input v-model="model.invoiceno" placeholder="多个发票号请以逗号“，”分隔开"></el-input>
                    </el-form-item>
                </el-col> -->
        <el-col :span="12">
          <el-form-item label="客户ERP编号" prop="erpcode" :rules="rules.validateRequire">
            <el-input v-model="model.erpcode"></el-input>
          </el-form-item>
          <el-col :span="12">
            <el-form-item label="开票日期" prop="invoicedate" :rules="rules.validateRequire">
              <el-date-picker v-model="model.invoicedate" type="date" placeholder="开票日期" value-format="yyyy-MM-dd" style="width:160px"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-col>
      </el-row>
      <!-- <el-row>
                <el-col :span="12">
                    <el-form-item label="快递单号" prop="couriernumber" :rules="rules.validateRequire">
                        <el-input v-model="model.couriernumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="快递方式" prop="courier" :rules="rules.validateRequire">
                        <el-select v-model="model.courier" filterable clearable>
                            <el-option v-for="item in codeModel.courierList" :key="item.code" :label="item.name" :value="item.code" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="开票金额" prop="invoicemoney" :rules="rules.validateRequire">
                        <el-input-number v-model="model.invoicemoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="发票类型" prop="invoicetype" :rules="rules.validateRequire">
                        <el-select v-model="model.invoicetype" filterable clearable>
                            <el-option v-for="item in codeModel.invoicetypeList" :key="item.code" :label="item.name" :value="item.code" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="开票日期" prop="invoicedate" :rules="rules.validateRequire">
                        <el-date-picker v-model="model.invoicedate" type="date" placeholder="开票日期" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="寄出日期" prop="maildate" :rules="rules.validateRequire">
                        <el-date-picker v-model="model.maildate" type="date" placeholder="寄出日期" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收件人" prop="receiver" :rules="rules.validateRequire">
                        <el-input v-model="model.receiver"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收件人电话" prop="receivertel" :rules="rules.validateRequire">
                        <el-input v-model="model.receivertel"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="邮寄地址" prop="mailaddress" :rules="rules.validateRequire">
                        <el-input v-model="model.mailaddress"></el-input>
                    </el-form-item>
                </el-col>
            </el-row> -->
    </el-form>
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit || disableSave">
      <el-row>
        <el-col :span="24">
          <el-divider content-position="center"><span>【以下信息为只读信息】</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-divider content-position="left"><span>【项目】相关信息</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="项目" prop="projectid" :required="true">
            <el-input v-model="model.dispprojectid" :disabled="true" class="tl-ref-selector">
              <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmProjectRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目编号">
            <el-input v-model="model.projectcode" :disabled="true"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="合同金额">
            <el-input-number v-model="model.projectcontractmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目金额">
            <el-input-number v-model="model.projectmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="已开票金额">
            <el-input-number v-model="model.projectbillmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="已收款金额">
            <el-input-number v-model="model.projectrecbillmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
            <span>元</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-divider content-position="left"><span>【业务类型】相关信息</span></el-divider>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="业务类型" prop="category">
            <el-select v-model="model.category" filterable clearable>
              <el-option v-for="item in codeModel.categoryList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原发票号" prop="oldinvoicecode" v-show="isCancelAndReadd">
            <el-input v-model="model.oldinvoicecode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form class="tl-form" ref="categoryform" :model="model" :rules="rules" label-width="120px" v-show="isCancelAndReadd" :disabled="disableEditSubmit || disableSave">
        <el-row>
          <el-col :span="12">
            <el-form-item label="原发票邮寄单号" prop="oldnumber">
              <el-input v-model="model.oldnumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-show="isCancelAndReadd">
            <el-form-item label="原客户名称" prop="oldcustomername">
              <el-input v-model="model.oldcustomername"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="原开票日期" prop="oldinvoicedate">
              <el-date-picker v-model="model.oldinvoicedate" type="date" placeholder="原开票日期" value-format="yyyy-MM-dd"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原开票金额" prop="oldinvoicemoney">
              <el-input-number v-model="model.oldinvoicemoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%"></el-input-number>
              <span>元</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <el-col :span="24" v-show="model.category == '3'">
          <el-form-item label="重开原因" prop="reinvoicereason">
            <el-input v-model="model.reinvoicereason" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" v-show="model.category == '2'">
          <el-form-item label="作废原因" prop="cancelreason">
            <el-input v-model="model.cancelreason" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form class="tl-form" ref="invoiceform" :model="model" :rules="rules" label-width="120px" v-show="isAddAndReadd" :disabled="disableEditSubmit || disableSave">
        <el-row>
          <el-col :span="24">
            <el-divider content-position="left"><span>【发票】相关信息</span></el-divider>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="发票开具单位" prop="invoiceorgname">
              <tl-ref-org v-model="model.invoiceorgname" :initDisplayData.sync="model.invoiceorgname" dataType="code" :singleSelect="true" @confirm="onSelectOrg" :disabled="disableEditSubmit || disableSave" :externalQueryParam="{qry_enabled:1}"></tl-ref-org>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发票所属部门" prop="invoicedeptname">
              <tl-ref-dept v-model="model.invoicedeptname" :initDisplayData.sync="model.invoicedeptname" dataType="code" nameType="fullname" :singleSelect="true" @confirm="onSelectDept" :disabled="disableEditSubmit || disableSave" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="发票类型" prop="invoicetype">
              <el-select v-model="model.invoicetype" filterable clearable>
                <el-option v-for="item in codeModel.invoicetypeList" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开票金额" prop="invoicemoney">
              <el-input-number v-model="model.invoicemoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%"></el-input-number>
              <span>元</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="开票要求" prop="demand">
              <el-input v-model="model.demand" type="textarea" :rows="2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="税收类别" prop="explain">
              <!-- <el-input v-model="model.explain" type="textarea" :rows="2"></el-input> -->
              <el-select v-model="model.explain" filterable clearable>
                <el-option v-for="item in codeModel.invgoodscodeList" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称" prop="customername">
              <el-input v-model="model.customername" :disabled="true" class="tl-ref-selector">
                <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                        <el-form-item label="开票标识" prop="invoiceflag" :required="true" :rules="rules.validateRequire">
                            <el-input v-model="model.invoiceflag" :disabled="true" class="tl-ref-selector">
                                <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerBillRefDialog" v-if="!disableEditSubmit"></el-button>
                            </el-input>
                        </el-form-item>
                    </el-col> -->
          <el-col :span="12">
            <el-form-item label="企业名称" prop="companyname">
              <el-input v-model="model.companyname" :disabled="true" class="tl-ref-selector">
                <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerBillRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ERP销售单号" prop="erpdocno" v-show="isAddAndReadd">
              <el-input v-model="model.erpdocno" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="企业地址" prop="companyaddress">
              <el-input v-model="model.companyaddress" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="税号" prop="taxno">
              <el-input v-model="model.taxno" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="companytel">
              <el-input v-model="model.companytel" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开户行" prop="bankname">
              <el-input v-model="model.bankname" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行账户" prop="bankaccount">
              <el-input v-model="model.bankaccount" :readonly="true" class="is-disabled"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="账期方式" prop="paymethod">
              <el-row>
                <el-col :span="22">
                  <el-input v-model="model.paymethod" :disabled="true" class="tl-ref-selector">
                    <el-button slot="append" type="primary" icon="el-icon-search" @click="openTlErpAccountPeriodDialog"></el-button>
                  </el-input>
                </el-col>
                <el-col :span="2">
                  <tl-help>
                    如果项目只有一个合同，则将合同中的账期方式、账期名称、ERP来源编码自动带出；
                    如果项目有多个合同，则需要手动选择。
                  </tl-help>
                </el-col>
              </el-row>
              <!-- <erp-account-period v-model="model.paymethod" :initDisplayData.sync="model.paymethod" :singleSelect="true"></erp-account-period> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账期名称" prop="payname">
              <el-input v-model="model.payname" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="ERP来源编码" prop="erpsourcecode" v-show="isAddAndReadd">
              <el-input v-model="model.erpsourcecode" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
                    <el-col :span="12">
                        <el-form-item label="收件人" prop="receiver">
                            <el-input v-model="model.receiver" :readonly="true" class="is-disabled"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="收件人电话" prop="receivertel">
                            <el-input v-model="model.receivertel" :readonly="true" class="is-disabled"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="邮寄地址" prop="mailaddress">
                            <el-input v-model="model.mailaddress" :readonly="true" class="is-disabled"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row> -->
      </el-form>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- <el-row>
                <el-col :span="12">
                    <el-form-item label="申请公司编码" prop="orgcode">
                        <el-input v-model="model.orgcode"></el-input>
                    </el-form-item>
                </el-col>
            </el-row> -->
      <el-collapse>
        <el-collapse-item title="【单据】相关信息">
          <el-row>
            <el-col :span="12">
              <el-form-item label="经办部门" prop="deptname">
                <tl-ref-dept v-model="model.deptcode" :initDisplayData.sync="model.deptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="经办公司" prop="orgname">
                <el-input v-model="model.orgname" :readonly="true" class="is-disabled"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="经办人" prop="username">
                <tl-ref-user v-model="model.username" :initDisplayData.sync="model.username" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="经办人工号" prop="usercode">
                <el-input v-model="model.usercode" :readonly="true" class="is-disabled"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="单据日期" prop="docdate">
                <el-date-picker v-model="model.docdate" type="date" placeholder="单据日期" value-format="yyyy-MM-dd"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="提交时间" prop="submitdate">
                <el-date-picker v-model="model.submitdate" type="datetime" placeholder="提交时间" disabled></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="审批流程" prop="flowid">
                <!-- <el-select v-model="model.flowid" filterable clearable disabled>
                                    <el-option v-for="item in codeModel.flowidList" :key="item.id" :label="item.name" :value="parseInt(item.id)" />
                                </el-select> -->
                <el-input v-model="model.dispflowid" :readonly="true" class="is-disabled"> </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态" prop="state">
                <el-input v-model="model.dispstate" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <tl-approval-history ref="history" sourceType="PmInvoiceApply" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit" v-if="uiOperateState<=2">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave">
        <svg-icon icon-class="save" />保存
      </el-button>
      <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval">
        <svg-icon icon-class="send" />提交审批
      </el-button>
      <tl-attachment sourceType="PmInvoiceApply" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory">
        <svg-icon icon-class="list" />审批历史
      </el-button>
      <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval">
        <svg-icon icon-class="undo" />取消审批
      </el-button>
    </div>
    <tlpm-project-ref ref="pmProjectRef" @confirm="getpmProjectRefData" :isSingleSelect="true"></tlpm-project-ref>
    <tlpm-contract-ref ref="pmContractRef" @confirm="getpmContractRefData" :isSingleSelect="true" :externalQueryParam="{qry_projectid:model.projectid}"></tlpm-contract-ref>
    <tlpm-customer-ref ref="pmCustomerRef" @confirm="getpmCustomerRefData" :isSingleSelect="true"></tlpm-customer-ref>
    <tlpm-customer-bill-ref ref="pmCustomerBillRef" @confirm="getpmCustomerBillRefData" :isSingleSelect="true" :externalQueryParam="{qry_customerid:model.customerid}"></tlpm-customer-bill-ref>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlpmProjectRef from '@/views/ProjectManage/pmProject/refList.vue'
import tlpmContractRef from '@/views/ProjectManage/pmContract/refList.vue'
import tlpmCustomerRef from '@/views/ProjectManage/pmCustomer/refList.vue'
import tlHelp from '@/components/help/help'
import tlpmCustomerBillRef from '@/views/ProjectManage/pmCustomerBill/refList.vue'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_approval_edit],
  components: { tlpmProjectRef, tlpmContractRef, tlpmCustomerRef, tlpmCustomerBillRef, tlHelp },
  data() {
    return {
      moduleTitle: '项目合同开票申请',
      urlPrefix: '/pm/invoiceApply/',
      url: {
        // 额外的url
      }
    }
  },
  computed: {
    // 状态为新增或重开
    isAddAndReadd() {
      return this.model.category === '1' || this.model.category === '3'
    },
    // 状态为作废或重开
    isCancelAndReadd() {
      return this.model.category === '2' || this.model.category === '3'
    }
  },
  methods: {
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
          this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
        }
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'orgname', this.org.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'docdate', new Date())
      }
    },
    loaded() {
      // 页面加载完毕执行
      if (!this.isAdd && this.model.docno) {
        this.title = this.title + `（单据编号：${this.model.docno}）`
      }
      let { invoicedate, maildate } = this.model
      if (!invoicedate) {
        invoicedate = new Date()
      }
      if (!maildate) {
        maildate = new Date()
      }
      this.$set(this.model, 'invoicedate', invoicedate)
      this.$set(this.model, 'maildate', maildate)
    },
    onSelectDept(selectedDepts) {
      const selectedDept = selectedDepts[0]
      this.$set(this.model, 'invoicedeptname', selectedDept.fullname)
      this.$set(this.model, 'invoicedeptcode', selectedDept.code)
    },
    onSelectOrg(selectedOrgs) {
      const selectedOrg = selectedOrgs[0]
      this.$set(this.model, 'invoiceorgname', selectedOrg.name)
      this.$set(this.model, 'invoiceorgcode', selectedOrg.code)
    },
    /** 打开项目参照 */
    openpmProjectRefDialog() {
      this.$refs.pmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getpmProjectRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'projectid', selectionRow.id)
      this.$set(this.model, 'dispprojectid', selectionRow.name)
      this.$set(this.model, 'invoicedeptname', selectionRow.ownerdeptname)
      this.$set(this.model, 'invoicedeptcode', selectionRow.ownerdeptcode)
      this.$set(this.model, 'invoiceorgcode', selectionRow.ownerorgcode)
      this.$set(this.model, 'invoiceorgname', selectionRow.ownerorgname)
      this.$set(this.model, 'projectcode', selectionRow.code)
      this.$set(this.model, 'projectcontractmoney', selectionRow.contractmoney)
      this.$set(this.model, 'projectmoney', selectionRow.projectmoney)
      this.$set(this.model, 'projectrecbillmoney', selectionRow.recbillmoney)
      this.$set(this.model, 'projectbillmoney', selectionRow.billmoney)
    },
    /** 打开客户名称参照 */
    openpmCustomerRefDialog() {
      this.$refs.pmCustomerRef.visible = true
    },
    /** 获取客户名称参数数据 */
    getpmCustomerRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'customerid', selectionRow.id)
      this.$set(this.model, 'customername', selectionRow.name)
      this.$set(this.model, 'invoiceflag', '')
      this.$set(this.model, 'companyname', '')
      this.$set(this.model, 'companyaddress', '')
      this.$set(this.model, 'taxno', '')
      this.$set(this.model, 'companytel', '')
      this.$set(this.model, 'bankname', '')
      this.$set(this.model, 'bankaccount', '')
      this.$set(this.model, 'receiver', '')
      this.$set(this.model, 'receivertel', '')
      this.$set(this.model, 'mailaddress', '')
    },
    /** 打开开票标识参照 */
    openpmCustomerBillRefDialog() {
      if (this.model.customerid == null) {
        this.$message({
          message: '请先选择客户名称！',
          type: 'warning'
        })
        this.$refs.pmCustomerBillRef.visible = false
      } else {
        this.$refs.pmCustomerBillRef.visible = true
      }
    },
    /** 获取开票标识参数数据 */
    getpmCustomerBillRefData(selectionRow, selectKey, selectionValue) {
      this.$set(this.model, 'invoiceflag', selectionRow.id)
      this.$set(this.model, 'companyname', selectionRow.companyname)
      this.$set(this.model, 'companyaddress', selectionRow.companyaddress)
      this.$set(this.model, 'taxno', selectionRow.taxno)
      this.$set(this.model, 'companytel', selectionRow.companytel)
      this.$set(this.model, 'bankname', selectionRow.bankname)
      this.$set(this.model, 'bankaccount', selectionRow.bankaccount)
      this.$set(this.model, 'receiver', selectionRow.receiver)
      this.$set(this.model, 'receivertel', selectionRow.receivertel)
      this.$set(this.model, 'mailaddress', selectionRow.mailaddress)
    },
    saveCourierInfo(resolve, reject) {
      const {
        id,
        // invoiceno,
        erpcode
        // invoicemoney,
        // invoicetype,
        // invoicedate,
        // maildate,
        // receiver,
        // receivertel,
        // mailaddress,
        // courier,
        // couriernumber
      } = this.model
      // if (!invoiceno) {
      //     this.$tap.alert('请填写发票号码')
      //     reject()
      // }
      if (!erpcode) {
        this.$tap.alert('请填写客户ERP编号')
        reject()
      }
      // if (!invoicemoney) {
      //     this.$tap.alert('请填写开票金额')
      //     reject()
      // }
      // if (!invoicetype) {
      //     this.$tap.alert('请填写开票类型')
      //     reject()
      // }
      // if (!maildate) {
      //     this.$tap.alert('请填写寄出日期')
      //     reject()
      // }
      // if (!invoicedate) {
      //     this.$tap.alert('请填写开票日期')
      //     reject()
      // }
      // if (!receiver) {
      //     this.$tap.alert('请填写收件人')
      //     reject()
      // }
      // if (!receivertel) {
      //     this.$tap.alert('请填写收件人电话')
      //     reject()
      // }
      // if (!mailaddress) {
      //     this.$tap.alert('请填写邮寄地址')
      //     reject()
      // }
      // if (!courier) {
      //     this.$tap.alert('请填写快递方式')
      //     reject()
      // }
      // if (!couriernumber) {
      //     this.$tap.alert('请填写快递单号')
      //     reject()
      // }
      const param = {
        id,
        // invoiceno,
        erpcode
        // invoicemoney,
        // invoicetype,
        // invoicedate,
        // maildate,
        // receiver,
        // receivertel,
        // mailaddress,
        // courier,
        // couriernumber
      }
      putAction(this.url.edit, param)
        .then(res => {
          if (res.success) {
            resolve()
          } else {
            this.$tap.alert(res.message, 'warning')
            reject()
          }
        })
        .catch(err => {
          this.$tap.alert('保存客户编号失败，请联系系统管理员', 'warning')
          reject()
        })
    }
  }
}
</script>

